﻿using ConsoleApp2.Service;
using ConsoleApp2.Models;
using ConsoleApp2.User;

namespace ConsoleApp2.Impl;

public class LocalUserSystemServiceImpl : LocalUserSystemService
{
    private LocalUser LocalUser { get; set; }

    public LocalUserSystemServiceImpl()
    {
        LocalUser = new LocalUser();
    }

    public List<ConsoleApp2.Models.User> GetAllUsers()
    {
        return LocalUser.Users;
    }

    public void SaveUser(ConsoleApp2.Models.User user)
    {
        LocalUser.AddUser(user);
    }

    public bool DeleteUserById(int id)
    {
        if (id <= 0)
        {
            return false;
        }

        List<ConsoleApp2.Models.User> users = LocalUser.Users;
        ConsoleApp2.Models.User userToDelete = users.FirstOrDefault(u => u.Id == id);
        if (userToDelete != null)
        {
            users.Remove(userToDelete);
            return true;
        }
        return false;
    }
}